﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.CRM;
using Jzy.Model.CRM;
using Jzy.Core.Common.Web;
using Frame.Lib.Utilities;
using Frame.Lib.Common;


namespace Jzy.Web.CRM.SiteAccount
{
    public partial class Edit : PageEdit
    {
        private SiteAccountBO _siteAccount;
        private SiteAccountBO SiteAccount
        {
            get
            {
                if (_siteAccount == null)
                {
                    _siteAccount = new SiteAccountBO();
                }
                return _siteAccount;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(this.PKID))
                {
                    DispInfo();
                }
                else
                {
                    IsPublic.Checked = true;
                }
            }
        }

        private void DispInfo()
        {
            SiteAccountInfo info = this.SiteAccount.GetInfo(PKID);

            EntityUtil.SetControl(pnlMain, info);

            Password.Text = info.DecryptPassword;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            SiteAccountInfo info = this.SiteAccount.GetInfo(PKID);
            EntityUtil.SetEntity(pnlMain, info);
            info.Password = StrUtil.EncryptDES(Password.Text.Trim());
            if (string.IsNullOrEmpty(PKID))
            {
                info.InputTime = DateTime.Now;
                info.IsDelete = false;
               // info.IsPublic = true;
                info.CreatorID = AppSession.UserID;
                info.CreatorName = AppSession.UserName;
                
            }


            this.SiteAccount.Save(info);

            JSUtil.RefreshView();
        }
    }
}
